package com.traffic.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.security.utils.BaseUtil;
import com.traffic.domain.FamilyCriminal;
import com.traffic.service.IFamilyCriminalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 用户亲属犯罪信息Controller
 *
 * @author zzs
 * @date 2024-11-08
 */
@RestController
@RequestMapping("/criminal")
public class FamilyCriminalController extends BaseController
{
    @Autowired
    private IFamilyCriminalService familyCriminalService;

    /**
     * 查询用户亲属犯罪信息列表
     */
    @RequiresPermissions("information:criminal:list")
    @GetMapping("/list")
    public TableDataInfo list(FamilyCriminal familyCriminal)
    {
        startPage();
        Long curId= BaseUtil.getCurrentId();
        familyCriminal.setUserId(curId);
        List<FamilyCriminal> list = familyCriminalService.selectFamilyCriminalList(familyCriminal);
        return getDataTable(list);
    }

    /**
     * 导出用户亲属犯罪信息列表
     */
    @RequiresPermissions("information:criminal:export")
    @Log(title = "用户亲属犯罪信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FamilyCriminal familyCriminal)
    {
        List<FamilyCriminal> list = familyCriminalService.selectFamilyCriminalList(familyCriminal);
        ExcelUtil<FamilyCriminal> util = new ExcelUtil<FamilyCriminal>(FamilyCriminal.class);
        util.exportExcel(response, list, "用户亲属犯罪信息数据");
    }

    /**
     * 获取用户亲属犯罪信息详细信息
     */
    @RequiresPermissions("information:criminal:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(familyCriminalService.selectFamilyCriminalById(id));
    }

    /**
     * 新增用户亲属犯罪信息
     */
    @RequiresPermissions("information:criminal:add")
    @Log(title = "用户亲属犯罪信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FamilyCriminal familyCriminal)
    {
        Long curId= BaseUtil.getCurrentId();
        familyCriminal.setUserId(curId);
        return toAjax(familyCriminalService.insertFamilyCriminal(familyCriminal));
    }

    /**
     * 修改用户亲属犯罪信息
     */
    @RequiresPermissions("information:criminal:edit")
    @Log(title = "用户亲属犯罪信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FamilyCriminal familyCriminal)
    {
        return toAjax(familyCriminalService.updateFamilyCriminal(familyCriminal));
    }

    /**
     * 删除用户亲属犯罪信息
     */
    @RequiresPermissions("information:criminal:remove")
    @Log(title = "用户亲属犯罪信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(familyCriminalService.deleteFamilyCriminalByIds(ids));
    }
}
